package model;

import org.hibernate.annotations.Tables;

import javax.persistence.*;
import java.util.Set;
import java.util.StringTokenizer;

/**
 * User: Станислав
 * Date: 17.08.14
 */
@Entity
@Table(name = "album")
public class Album {
    @Id

    @Column(name = "album_id")
    private long id;
    @Column(name = "name")
    private String name;
    @ManyToMany
    @JoinTable(name = "photo_album",
            joinColumns = @JoinColumn(name = "album_id"),
            inverseJoinColumns = @JoinColumn(name = "photo_id"))
    private Set<Photo> photoSet;

    public Album(int id, String name, Set<Photo> photoSet) {
        this.id = id;
        this.name = name;
        this.photoSet = photoSet;
    }

    public long getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Set<Photo> getPhotoSet() {
        return photoSet;
    }

    public void setPhotoSet(Set<Photo> photoSet) {
        this.photoSet = photoSet;
    }

    public Album(String fromFile) {
        StringTokenizer tokenizer = new StringTokenizer(fromFile, "|*|");
        this.id = Integer.parseInt(tokenizer.nextToken());
        this.name = tokenizer.nextToken();

    }

    @Override
    public String toString() {
        return "Album{" +
                "album_id=" + id +
                ", name='" + name + '\'' +
                ", photoSet=" + photoSet +
                '}';
    }
}
